package com.scalar.chiptrack.workflow;

import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Map;

import com.jgraph.graph.DefaultGraphCell;

/**
 * User: Murali Krishna Yengala
 * Date: Apr 28, 2005
 * Time: 4:29:06 PM
 */
public class CustomActivity {
    boolean isAbsolutePositioned = true;
    int relX = 0;
    int relY = 0;

    int absX = 0;
    int absY = 0;

    DefaultGraphCell activity = null;
    Map attribs = null;
    Rectangle bounds = null;
    int inbounds;
    int outbounds;


    DefaultGraphCell parentActivity = null;
    Map parentAttribs = null;
    Rectangle parentBounds = null;
    int parentOutbounds;
    int parentInbounds;

    ArrayList children = null;

    CustomActivity refCustomActivity = null;
    CustomActivity ca_parent = null;
    CustomActivity ca_prevSibling = null;

    boolean isProcessed = false;

    public boolean isAbsolutePositioned() {
        return isAbsolutePositioned;
    }

    public void setAbsolutePositioned(boolean absolutePositioned) {
        isAbsolutePositioned = absolutePositioned;
    }

    public int getRelX() {
        return relX;
    }

    public void setRelX(int relX) {
        this.relX = relX;
    }

    public int getRelY() {
        return relY;
    }

    public void setRelY(int relY) {
        this.relY = relY;
    }

    public int getAbsX() {
        int tmpX = 0;
        if( isAbsolutePositioned() )
        {
            tmpX = this.absX;
        }
        else
        {
            if( refCustomActivity != null)
            {
                tmpX = this.refCustomActivity.getAbsX() + this.relX;
            }
            else
            {
                tmpX = this.relX;
            }
        }
        return tmpX;
    }

    public void setAbsX(int absX) {
        this.absX = absX;
    }

    public int getAbsY() {
        int tmpY = 0;
        if( isAbsolutePositioned() )
        {
            tmpY = this.absY;
        }
        else
        {
            if( getCa_parent() != null && !getCa_parent().isAbsolutePositioned() )
            {
                tmpY = this.ca_parent.getAbsY() + this.relY;
            }
            else
            {
                if( refCustomActivity != null)
                {
                    tmpY = this.refCustomActivity.getAbsY() + this.relY;
                }
                else
                {
                    tmpY = this.relY;
                }
            }

        }
        return tmpY;
    }

    public void setAbsY(int absY) {
        this.absY = absY;
    }

    public DefaultGraphCell getActivity() {
        return activity;
    }

    public void setActivity(DefaultGraphCell activity) {
        this.activity = activity;
    }

    public Map getAttribs() {
        return attribs;
    }

    public void setAttribs(Map attribs) {
        this.attribs = attribs;
    }

    public Rectangle getBounds() {
        return bounds;
    }

    public void setBounds(Rectangle bounds) {
        this.bounds = bounds;
    }

    public int getInbounds() {
        return inbounds;
    }

    public void setInbounds(int inbounds) {
        this.inbounds = inbounds;
    }

    public int getOutbounds() {
        return outbounds;
    }

    public void setOutbounds(int outbounds) {
        this.outbounds = outbounds;
    }

    public DefaultGraphCell getParentActivity() {
        return parentActivity;
    }

    public void setParentActivity(DefaultGraphCell parentActivity) {
        this.parentActivity = parentActivity;
    }

    public Map getParentAttribs() {
        return parentAttribs;
    }

    public void setParentAttribs(Map parentAttribs) {
        this.parentAttribs = parentAttribs;
    }

    public Rectangle getParentBounds() {
        return parentBounds;
    }

    public void setParentBounds(Rectangle parentBounds) {
        this.parentBounds = parentBounds;
    }

    public int getParentOutbounds() {
        return parentOutbounds;
    }

    public void setParentOutbounds(int parentOutbounds) {
        this.parentOutbounds = parentOutbounds;
    }

    public int getParentInbounds() {
        return parentInbounds;
    }

    public void setParentInbounds(int parentInbounds) {
        this.parentInbounds = parentInbounds;
    }

    public CustomActivity getRefCustomActivity() {
        return refCustomActivity;
    }

    public void setRefCustomActivity(CustomActivity refCustomActivity) {
        this.refCustomActivity = refCustomActivity;
    }

    public ArrayList getChildren() {
        return children;
    }

    public void setChildren(ArrayList children) {
        this.children = children;
    }

    public CustomActivity getCa_parent() {
        return ca_parent;
    }

    public void setCa_parent(CustomActivity ca_parent) {
        this.ca_parent = ca_parent;
    }

    public CustomActivity getCa_prevSibling() {
        return ca_prevSibling;
    }

    public void setCa_prevSibling(CustomActivity ca_prevSibling) {
        this.ca_prevSibling = ca_prevSibling;
    }


    public boolean isProcessed() {
        return isProcessed;
    }

    public void setProcessed(boolean processed) {
        isProcessed = processed;
    }

    public String toString()
    {
        return this.getActivity().toString()+" - "+ (this.isAbsolutePositioned()?"ABSOLUTE ":"RELATIVE ") +" -R:("+this.relX+","+this.relY+") - A:("+this.absX+","+this.absY+") - "+(isProcessed()?"PROCESSED":"NOT PROCESSED");
    }

}
